<template>
  <el-dialog title="系数配置" :close-on-click-modal="false" @close="end" :visible.sync="visible" width="800px">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="150px">
      <el-form-item label="部门系数" prop="config01">
        <el-input-number size="medium" v-model="dataForm.config01" style="width: 90%;"></el-input-number>
      </el-form-item>
      <el-form-item label="部门考核基础分" prop="config02">
        <el-input-number size="medium" v-model="dataForm.config02" style="width: 90%;"></el-input-number>
      </el-form-item>
      <el-form-item label="部门考核分级" prop="config03">
        <el-select :clearable="true" v-model="dataForm.config03" placeholder="请选择部门考核分级" class="xiaLa" style="width: 90%;">
          <el-option
            v-for="(item,index) in  [{label:'A',value:'A'},{label:'B',value:'B'},{label:'C',value:'C'},{label:'D',value:'D'}]"
            :key="index" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
      <el-button type="primary" plain @click="end">取消</el-button>
    </span>
  </el-dialog>
</template>
<script>
/*!
 * 系数配置_分组_全部
 *
 * @author shf
 * @date 2021-9-6 15:04:39
 */

import {saveOrUpdatByDeptCodeFz, saveOrUpdatByDeptCodeQb,getByDeptCode} from '@/api/jiangjin/jiangjinjggxxspz'

export default {
  data() {
    return {
      visible: false,
      canSubmit: false,
      dataForm: {
        config01: '',
        config02: '',
        config03: '',
      },
      dataRule: {
        config01: [{
          required: true,
          message: '部门系数不能为空',
          trigger: 'blur'
        }],
        // config02: [{
        //   required: true,
        //   message: '部门考核基础分不能为空',
        //   trigger: 'blur'
        // }],
        // config03: [{
        //   required: true,
        //   message: '部门考核分级 ABCD不能为空',
        //   trigger: 'blur'
        // }]
      },
      id: '',
      bz: ''
    }
  },
  methods: {
    init(bz, id, info) {
      this.visible = true;
      this.canSubmit = true;
      this.bz = bz;
      this.id = id;
      if(info){
        getByDeptCode(info).then(response => {
          if(response.data.data){
            this.dataForm.config01 = response.data.data.config01;
            this.dataForm.config02 = response.data.data.config02;
            this.dataForm.config03 = response.data.data.config03;
          }
        })
      }
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.canSubmit = false;
          //fzCode值为all时则是 全部系数配置，值为数字时则是分组系数配置
          (this.bz == "all"
              ? saveOrUpdatByDeptCodeQb(this.dataForm, this.id)
              : saveOrUpdatByDeptCodeFz(this.dataForm, this.id)
          )
            .then(data => {
              this.$notify.success('配置成功')
              this.dataForm = {
                config01: '',
                config02: '',
                config03: '',
              };
              this.visible = false;
              this.$emit("refresh");
            }).catch(() => {
            this.canSubmit = true;

          });

        }
      })
    },
    end() {
      this.dataForm = {
        config01: '',
        config02: '',
        config03: '',
      }
      this.visible = false
    }
  }
}

</script>
